package com.localjoycommunity.cpdj.project.system.service.impl;

import com.localjoycommunity.cpdj.common.constant.Constants;
import com.localjoycommunity.cpdj.common.utils.DateUtils;
import com.localjoycommunity.cpdj.common.utils.file.Base64ToMultipartFile;
import com.localjoycommunity.cpdj.common.utils.file.FileUploadUtils;
import com.localjoycommunity.cpdj.project.system.domain.SysBeauty;
import com.localjoycommunity.cpdj.project.system.mapper.SysBeautyMapper;
import com.localjoycommunity.cpdj.project.system.service.ISysBeautyService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.web.multipart.MultipartFile;

import java.util.List;

/**
 * 风采展示Service业务层处理
 *
 * @author leepandar
 * @date 2020-10-30
 */
@Service
public class SysBeautyServiceImpl implements ISysBeautyService {
    @Autowired
    private SysBeautyMapper sysBeautyMapper;

    /**
     * 查询风采展示
     *
     * @param beautyId 风采展示ID
     * @return 风采展示
     */
    @Override
    public SysBeauty selectSysBeautyById(Long beautyId) {
        return sysBeautyMapper.selectSysBeautyById(beautyId);
    }

    /**
     * 查询风采展示app
     *
     * @param beautyId 风采展示ID
     * @return 风采展示
     */
    @Override
    public SysBeauty selectAppSysBeautyById(Long beautyId) {
        SysBeauty sysBeauty = sysBeautyMapper.selectSysBeautyById(beautyId);
        sysBeauty.setViewNum(sysBeauty.getViewNum() == null ? 1 : sysBeauty.getViewNum() + 1);
        sysBeautyMapper.updateSysBeauty(sysBeauty);
        return sysBeauty;
    }

    /**
     * 查询风采展示列表
     *
     * @param sysBeauty 风采展示
     * @return 风采展示
     */
    @Override
    public List<SysBeauty> selectSysBeautyList(SysBeauty sysBeauty) {
        return sysBeautyMapper.selectSysBeautyList(sysBeauty);
    }

    /**
     * 新增风采展示
     *
     * @param sysBeauty 风采展示
     * @return 结果
     */
    @Override
    public int insertSysBeauty(SysBeauty sysBeauty) {
        sysBeauty.setCreateTime(DateUtils.getNowDate());
        return sysBeautyMapper.insertSysBeauty(sysBeauty);
    }

    /**
     * 修改风采展示
     *
     * @param sysBeauty 风采展示
     * @return 结果
     */
    @Override
    public int updateSysBeauty(SysBeauty sysBeauty) {
        sysBeauty.setUpdateTime(DateUtils.getNowDate());
        return sysBeautyMapper.updateSysBeauty(sysBeauty);
    }


    /**
     * 风采展示点赞
     *
     * @param sysBeauty 风采展示
     * @return 结果
     */
    @Override
    public int updateSysBeautyClickNum(SysBeauty sysBeauty) {
        sysBeauty.setUpdateTime(DateUtils.getNowDate());
        sysBeauty.setClickNum(sysBeauty.getClickNum() == null ? 1 : sysBeauty.getClickNum() + 1);
        return sysBeautyMapper.updateSysBeauty(sysBeauty);
    }

    /**
     * 批量删除风采展示
     *
     * @param beautyIds 需要删除的风采展示ID
     * @return 结果
     */
    @Override
    public int deleteSysBeautyByIds(Long[] beautyIds) {
        return sysBeautyMapper.deleteSysBeautyByIds(beautyIds);
    }

    /**
     * 删除风采展示信息
     *
     * @param beautyId 风采展示ID
     * @return 结果
     */
    @Override
    public int deleteSysBeautyById(Long beautyId) {
        return sysBeautyMapper.deleteSysBeautyById(beautyId);
    }

    /**
     * 增加点赞数
     *
     * @param id
     * @param num
     */
    @Override
    public int updateDigNum(long id, int num) {
        return sysBeautyMapper.updateLikeNum(id, num);
    }
}
